package LeetCode;

import java.util.Arrays;

/**
 * LCR 179. 查找总价格为目标值的两个商品
 * https://leetcode.cn/problems/he-wei-sde-liang-ge-shu-zi-lcof/description/
 */
class Solution4 {
    public int[] twoSum(int[] price, int target) {
        int left = 0;
        int right = price.length - 1;
        int[] result = new int[2];
        while(left < right) {
            if(price[left] + price[right] > target) {
                right--;
            } else if(price[left] + price[right] < target) {
                left++;
            } else {
                result[0] = price[left];
                result[1] = price[right];
                return result;
            }
        }
        return null;
    }
}